<?php
class Course
{
	private $id;
	private $name;
	private $courseHour;
	private $major;

           /**
            * 一门课程拥有一个任课教师
            *
            * @var Tearcher
            */
	private $teacher;

           /**
            * 构造函数，在创建对象实例时，自动调用做初始化操作
            */
	public function __construct($id, $name, $courseHour, $major)
	{
		$this->id = $id;
		$this->name = $name;
		$this->courseHour = $courseHour;
		$this->major = $major;
	}

	public function __get($name)
	{
		if(property_exists(self::class, $name)) {
			return $this->$name;
		}
		return null;
	}

	public function __set($name, $value)
	{
		if (property_exists(self::class, $name)) {
			$this->$name = $value;
		}
	}

           // 把当前对象转换成字符串形式，当直接输出该类的对象实例时，自动调用
	public function __tostring() 
	{
		return 'id: ' . $this->id . ' 课程: ' . $this->name . ' 课时: ' . $this->courseHour . ' 专业: ' . $this->major . '<br/>' . '任课教师: ' . $this->teacher->name; 
	}
}
